const mongoose = require('mongoose')
const mongoosePaginate = require('mongoose-paginate')
const path = require('path')

module.exports = function (db) {
    return db.model(path.basename(__filename, path.extname(__filename)), new mongoose.Schema(
        {
            code: {
                type: String,
                unique: true,
                required: true,
                index: true,
            },

            name: {
                type: String,
                index: true,
            },

            // 是否可用 1=可用，2=不可用
            is_enable: {
                type: Number,
                default: 1,
            },

            // 是否删除 1=未删除，2=已删除
            is_delete: {
                type: Number,
                default: 1,
            },

            //创建时间
            created_at: {
                type: Date,
                index: true,
                default: Date.now
            },

            updated_at: {
                type: Date,
                default: Date.now
            },
        },
        {
            collection: path.basename(__filename, path.extname(__filename)),
            timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }
        }).plugin(mongoosePaginate)
    )
}
